<template>
  <div class="user-dialog">
    <el-dialog :title="formTitle" :visible.sync="visible" height="700px" width="80%" :close-on-click-modal=false
               @close="dialogClose">
      <el-form ref="plcDeviceForm" :model="dataForm" :label-width="formLabelWidth">
        <el-form-item label="用户名称">
          <el-input v-model="dataForm.user_name"></el-input>
        </el-form-item>
        <el-form-item label="登录名称">
          <el-input v-model="dataForm.login_name"></el-input>
        </el-form-item>
        <el-form-item label="电话号码">
          <el-input v-model="dataForm.mobile"></el-input>
        </el-form-item>
        <el-form-item label="用户类型">
          <el-select v-model="dataForm.group_id" placeholder="请选择">
            <el-option
              v-for="item in groupOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="所属企业">
          <el-select v-model="dataForm.enterprise_id" placeholder="请选择">
            <el-option
              v-for="item in enterpriseOptions"
              :key="item.value"
              :label="item.name"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="reset">重 置</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </div>
    </el-dialog>

  </div>

</template>

<script>


  export default {
    name: "index",
    methods: {
      setForm(rowForm) {
        let me = this;
        this.visible = true;
        if (rowForm) {
          rowForm['action_type'] = 'userUpdate';
          if(rowForm.enterprise_id) rowForm.enterprise_id = parseInt(rowForm.enterprise_id);
          this.dataForm = rowForm;
        } else {
          this.dataForm['action_type'] = 'userAdd';
        }
      },
      reset() {
        this.dataForm = {
          user_name: null,
          login_name: null,
          mobile:null,
          group_id: null,
          enterprise_id:null
        };
      },
      submit() {
        let me = this;
        this.$axios.post('userConfigRoutes',me.dataForm).then(function () {
          me.visible = false;
          me.$parent.queryData();
        });
      },
      dialogClose() {
        this.reset();
      }
    },
    data() {
      return {
        dataForm : {
          user_name: null,
          login_name: null,
          mobile:null,
          group_id: null,
          enterprise_id:null
        },
        groupOptions: [{
          value: '1',
          label: '超级管理员'
        }, {
          value: '2',
          label: '企业管理员'
        }],
        enterpriseOptions:[],
        visible: false,
        formTitle: '用户窗口',
        formLabelWidth: '120px'
      }
    },
    created(){
      let me = this;
      this.$axios.post('enterpriseRoutes',
        {
          action_type: 'enterpriseComboSetting',
        }).then(function (response) {
        me.enterpriseOptions = response.data.data;
      });
    }
  }
</script>

<style lang="scss">
  .user-dialog {
    .el-dialog__header {
      padding: 20px 20px 10px;
      background-color: #40c9c6;
    }
    .el-dialog__title {
      line-height: 24px;
      font-size: 18px;
      text-align: left;
      font-weight: bold;
      color: #f1fdff;
    }
  }
</style>
